<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网页刮刮卡</title>
    <style>
        .img {
            width: 400px;
            height: 300px;
            position: absolute;
            left: 200px;
            z-index: -1;
        }
        canvas {
            margin-left: 200px;
        }
        body {
            margin: 0;
        }
    </style>
</head>
<body>
    <div class="img">
        <img src="./images/prize.png" style="width:100%;height:100%;" />
    </div>
    <canvas id="canvas" width="400" height="300"></canvas>

    <script>
        let canvas = document.querySelector("#canvas");
        let context = canvas.getContext("2d");
        context.fillStyle = "rgba(0, 133, 255, 1)";   // 修改遮罩层颜色为蓝色
        context.fillRect(0, 0, 400, 300);
        canvas.addEventListener("mousemove", (e) => {
            if (e.buttons === 1) {
                const rect = canvas.getBoundingClientRect();
                const x = e.clientX - rect.left;
                const y = e.clientY - rect.top;
                context.globalCompositeOperation = "destination-out";
                context.beginPath();
                context.arc(x, y, 10, 0, Math.PI * 2);
                context.fill();
            }
        });
    </script>
</body>
</html>